Hello everyone. I am very new to API and this kind of programming in general (though I am getting the hang of the HTML and CSS) and I am attempting to have a change in one attribute cause another attribute to have a different value based on how much it has changed. The basic idea is that my sheet has an exhaustion (that you can change by 1 up to the max) and a max exhaustion value. A disadvantage die (d4) is added to a roll if your exhaustion is equal to half your exhaustion (so if you have 2 exhaustion, and 4 max, you have a d4 of disadvantage), and this die type is increased (d6, d8, d10, d12) for every 2 levels you go above half your exhaustion (until you get to max, and then you are incapacitated). My current script was cobbled together from a few different API examples with probably some misunderstanding of how the scripts work together and is below. on("change:exhaustion_level", function(eventinfo) {
const newValue = parseInt(eventinfo.newValue) || 0, previousValue = parseInt(eventinfo.previousValue) || 0;
let update = {};
if (newValue === 0) {
setAttrs({
exhaustion_tracking: 0
});
} else if (newValue == (getAttrByName(exhaustion_max) / 2)) {
setAttrs({
exhaustion_tracking: d4
});
} else if (newValue == ((getAttrByName(exhaustion_max) / 2) + 2) && newValue < (getAttrByName(exhaustion_max)) {
setAttrs({
exhaustion_tracking: d6
});
} else if (newValue == ((getAttrByName(exhaustion_max) / 2) + 4) && newValue < (getAttrByName(exhaustion_max)) {
setAttrs({
exhaustion_tracking: d8
});
} else if (newValue == ((getAttrByName(exhaustion_max) / 2) + 6) && newValue < (getAttrByName(exhaustion_max)) {
setAttrs({
exhaustion_tracking: d10
});
} else if (newValue == ((getAttrByName(exhaustion_max) / 2) + 8) && newValue < (getAttrByName(exhaustion_max)) {
setAttrs({
exhaustion_tracking: d12
});
} else {
setAttrs({
exhaustion_tracking: incap.
});
};
setAttrs(update, {silent: true});
}); I am pretty sure the setAttrs is updating the attribute, or at least it should if the values are passed in correctly. The code that takes the updated values is below, <div class="subcontainer" style="height: min-content; width: 70px;">
<div class="top">
<span style="font-size: 12px;">Current</span>
<input type="number" name="attr_exhaustion" title="@{exhaustion}" class="sheet-biomenu" min = "0" max="@{exhaustion_max}" step="1">
</div>
<span style="font-size: 12px;">Total</span>
<input type="number" name="attr_exhaustion_max" title="@{exhaustion_max}" class="sheet-biomenu" disabled="true" value="(@{physical_injuries_max}) + (@{mental_injuries_max})">
</div> <span>Toggle Exh. Tracking:</span>
<div>
<input class="toggle-left" name="attr_exhaustion_effect_toggle" type="radio" title="@{exhaustion_disadvantage}" value="0" checked="checked"/><span>Off</span>
<input class="toggle-right" name="attr_exhaustion_effect_toggle" type="radio" title="@{exhaustion_disadvantage}" value="1@{tracked_exhaustion}!"/><span>On</span>
</div>
<div>Dis. Level:<input type="number" name="attr_exhaustion_tracking" title="@{tracked_exhaustion}" class = "sheet-biomenu" disabled = "true" value="0">
</div> I am supposed to be passing in the values of exhaustion and max exhaustion, checking if the tracking is toggled through the radio selection, and then updating the die supposed to be rolled and the tracking field (the Dis. Level input which should show the dice value as d4, d6, d8, d10, d12). But after a lot of trial and error I can't tell if either is happening, or if my underlying script just doesn't work, or maybe even if the premise I am going for won't work. Any help is appreciated.